package org.oschina.api.upload.dao;

import java.util.List;
import org.oschina.Constants;
import org.oschina.api.BaseDAO;
import org.oschina.api.upload.model.UploadRecord;
import org.oschina.api.upload.vo.UploadRecordVo;
import org.springframework.stereotype.Repository;

@Repository
public class UploadRecordDAO extends BaseDAO {

	private final String findVo[]={"id","name","path","size","type","upload_time"};
	
	/**
	 * 返回
	 * @param first
	 * @param max
	 * @return
	 */
	public List<UploadRecordVo> findVo(int first,int max)
	{
		return getQueryHelper().query(findVo, null, new String[]{"ORDER BY upload_time DESC"}, null, UploadRecordVo.class, first, max);
	}
	
	/**
	 * 返回数量
	 * @return
	 */
	public int getCount()
	{
		return (int) getQueryHelper().queryDataSum(Constants.DB_UPLOAD_RECORD, null, null);
	}
	
	/**
	 * 创建
	 * @param uploadRecord
	 * @return
	 */
	public UploadRecord create(UploadRecord uploadRecord)
	{
		batchUpdate_queue("INSERT "+Constants.DB_UPLOAD_RECORD+"(id,name,path,size,type,upload_time) VALUES(?,?,?,?,?,?)", 
				new Object[]{uploadRecord.getId(),uploadRecord.getName(),uploadRecord.getPath(),uploadRecord.getSize(),uploadRecord.getType(),uploadRecord.getUpload_time()});
		return uploadRecord;
	}
}